home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / mac / Code / Chapter09 / ChangeTimeSensorsPanel.java < prev    next >
Text File  |  2000-08-29  |  1KB  |  68 lines

  1.  
  2. package applets;
  3.  
  4. import shout3d.*;
  5. import shout3d.core.*;
  6. import shout3d.math.*;
  7.  
  8.  
  9. public class ChangeTimeSensorsPanel extends Shout3DPanel implements DeviceObserver {
  10.    
  11.    TimeSensor timer;
  12.    TimeSensor timer2;
  13.  
  14.    boolean firstAnim = true;
  15.   
  16.  
  17.    public ChangeTimeSensorsPanel (Shout3DApplet applet){
  18.       super(applet);
  19.    }
  20.       
  21.    public void customInitialize() {
  22.       addDeviceObserver(this,"MouseInput", null);
  23.  
  24.  
  25.       timer = (TimeSensor) getNodeByName("timer");
  26.       timer2 = (TimeSensor) getNodeByName("timer2");               
  27.       
  28.       
  29.    }
  30.  
  31.  
  32.    protected void finalize()  { 
  33.       removeDeviceObserver(this,"MouseInput");
  34.  
  35.    }
  36.  
  37.    
  38.    
  39.    public boolean onDeviceInput(DeviceInput di, Object userData) {
  40.       MouseInput mi = (MouseInput) di;
  41.       switch (mi.which){
  42.  
  43.          case MouseInput.DOWN:
  44.          
  45.             if(firstAnim) {
  46.             
  47.                timer.stop();      
  48.                timer2.start();
  49.                               
  50.                firstAnim = false;   
  51.                return true;
  52.             }
  53.             else {
  54.             
  55.                timer2.stop();      
  56.                timer.start();
  57.                               
  58.                firstAnim = true;   
  59.                return true;
  60.             }
  61.                         
  62.       }//end of switch
  63.       
  64.       return false;
  65.    }
  66.  
  67.  
  68. }//end of class